using System;
using System.Collections.Generic;
namespace Lifter.Device.Dispatcher
{
    public class WorkItemComparer : IComparer<TransferWorkItem>
    {
        public int Compare(TransferWorkItem x, TransferWorkItem y)
        {
            int result;
            if (x == null && y == null)
            {
                return 0;
            }
            else if (x == null && y != null)
            {
                return 1;
            }
            else if (x != null && y == null)
            {
                return -1;
            }
            else
            {
                if (x.Priority < y.Priority)
                {
                    result = 1;
                }
                else if (x.Priority > y.Priority)
                {
                    result = -1;
                }
                else
                {
                    DateTime xQueuedTime = Convert.ToDateTime(x.QueuedTime);
                    DateTime yQueuedTime = Convert.ToDateTime(y.QueuedTime);
                    if (xQueuedTime < yQueuedTime)
                    {
                        result = -1;
                    }
                    else if (xQueuedTime > yQueuedTime)
                    {
                        result = 1;
                    }
                    else
                    {
                        result = 0;
                    }
                }
            }
            return result;
        }
    }
}
